{extend name='table'}

{block name="button"}
<!--{if auth("status")}-->
<a data-confirm="确定要禁用这些会员吗？" data-table-id="UserTable" data-action="{:url('status')}" data-rule="id#{id};status#0" class='layui-btn layui-btn-sm layui-btn-primary'>{:lang('批量禁用')}</a>
<!--{/if}-->
{/block}

{block name="content"}
<div class="layui-tab layui-tab-card">
    <div class="layui-tab-content">
        {include file='index/index_search'}
        <table id="UserTable" data-url="{:sysuri('index')}" data-target-search="form.form-search"></table>
    </div>
</div>
<script>
    $(function () {
        $('#UserTable').layTable({
            even: true, height: 'full',
            sort: {field: 'status,id', type: 'desc'},
            where: {type: '{$type|default="index"}'},
            cols: [[
                {checkbox: true, fixed: true},
                {
                    field: 'avatar', title: '{:lang("头像")}', width: 80, align: 'center', templet: function (d) {
                        if (!d.avatar) return '-';
                        return layui.laytpl('<div class="headimg headimg-ss shadow-inset margin-0" data-tips-image data-tips-hover data-lazy-src="{{d.avatar}}"></div>').render(d);
                    }
                },
                {field: 'nickname', title: '{:lang("昵称")}', minWidth: 100, align: 'center', templet: '<div>{{d.nickname||"-"}}</div>'},
                {field: 'openid', title: '{:lang("openId")}', minWidth: 100, align: 'center', templet: '<div>{{d.openid||"-"}}</div>'},
                {field: 'createtime', title: '{:lang("注册时间")}', align: 'center', minWidth: 170, sort: true},
                {field: 'realname', title: '{:lang("姓名")}', align: 'center', minWidth: 60},
				{field: 'mobile', title: '{:lang("电话")}', align: 'center', minWidth: 100},
				{field: 'weixin', title: '{:lang("微信号")}', align: 'center', minWidth: 80},
                {field: 'content', title: '{:lang("备注")}', align: 'center', minWidth: 90},				
                {toolbar: '#toolbar', title: '{:lang("操作")}', align: 'center', minWidth: 240, fixed: 'right'}
            ]]
        });

        // 数据状态切换操作
        layui.form.on('switch(StatusSwitch)', function (obj) {
            var data = {id: obj.value, status: obj.elem.checked > 0 ? 0 : 1};
            $.form.load("{:url('status')}", data, 'post', function (ret) {
                if (ret.code < 1) $.msg.error(ret.info, 3, function () {
                    $('#UserTable').trigger('reload');
                }); else {
                    $('#UserTable').trigger('reload')
                }
                return false;
            }, false);
        });
    });
</script>
<!-- 数据状态切换模板 -->
<script type="text/html" id="StatusSwitchTpl">
    <!--{if auth("state")}-->
    <input type="checkbox" value="{{d.id}}" lay-skin="switch" lay-text="{:lang('已激活')}|{:lang('已禁用')}" lay-filter="StatusSwitch" {{-d.status==0?'checked':''}}>
    <!--{else}-->
    {{-d.status==0 ? '<b class="color-green">{:lang("已激活")}</b>' : '<b class="color-red">{:lang("已禁用")}</b>'}}
    <!--{/if}-->
</script>

<script type="text/html" id="toolbar">
    <!--{if auth("edit")}-->
    <a class="layui-btn layui-btn-sm" data-event-dbclick data-title="{:lang('编辑用户')}" data-modal='{:url("edit")}?id={{d.id}}'>{:lang('编 辑')}</a>
    <a class="layui-btn layui-btn-sm" data-event-dbclick data-title="{:lang('发送消息')}" data-modal='{:url("send")}?id={{d.id}}'>{:lang('消 息')}</a>
    <!--{/if}-->
    <!--{if auth("remove")}-->
    <a class="layui-btn layui-btn-sm layui-btn-danger" data-confirm="{:lang('确定要永久删除吗？')}" data-action="{:url('remove')}" data-value="id#{{d.id}}">{:lang('删 除')}</a>
    <!--{/if}-->
</script>
{/block}
